﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EQual .Infrastructure .MVPFramework .Presenters ;
namespace EQual.MainModule.Employees.DetailsViews
{
    /// <summary>
    /// this is responsible for every secondary view about employees
    /// </summary>
    public class EmployeeDetailsPresenter : EQual .Infrastructure .MVPFramework .Presenters .ListPresenterBase <EmployeesExperianceView,DataAccesLayer .Employee  >
    {
 

        DataAccesLayer.EmployeeDataAccesLayer datalayer;

        public EmployeeDetailsPresenter()
        {
           datalayer = new DataAccesLayer.EQualDataLayerFactory().GetEmployeeAccesLayer();

           InitializeViews();

           View.ItemAdded += new EventHandler<Microsoft.Practices.Composite.Events.DataEventArgs<object >>(View_ItemAdded);
        }

        protected virtual void InitializeViews()
        {
            View = new EmployeesExperianceView();
        }

        void View_ItemAdded(object sender, Microsoft.Practices.Composite.Events.DataEventArgs<object > e)
        {
            datalayer.AddWorkingExperianceToEmployee(e.Value as DataAccesLayer .Work_Experiance ,ActiveItem );
        }
 
        public void DispalyEmployDetails(DataAccesLayer .Employee empl ) 
        {
            View.Model = new
            {
                ItemsCollection = datalayer.GetEmployeeExperience(empl)
            };
        }

        public override void Dispaly(DataAccesLayer.Employee item)
        {
            DispalyEmployDetails(item);
        }
    }
}
